﻿Imports System.IO

Public Class Settings

    Private Sub SaveButton_Click(sender As Object, e As EventArgs) Handles SaveButton.Click

        If DisableUpdatesBox.Checked Then
            INIs.INI_WriteValueToFile("PS Multi Tools", "AutoUpdate", "No", ".\conf.ini")
        Else
            INIs.INI_WriteValueToFile("PS Multi Tools", "AutoUpdate", "Yes", ".\conf.ini")
        End If

        If OffMode.Checked And NetModList.SelectedItem.ToString = "Disable PSMT when I'm offline" Then
            INIs.INI_WriteValueToFile("PS Multi Tools", "Offline", "Yes", ".\conf.ini")
        ElseIf OffMode.Checked And NetModList.SelectedItem.ToString = "Run PSMT even if offline" Then
            INIs.INI_WriteValueToFile("PS Multi Tools", "Offline", "No", ".\conf.ini")
        End If

    End Sub

    Private Sub SaveLanguage_Click(sender As Object, e As EventArgs) Handles SaveLanguage.Click

        If LangBox.SelectedItem.ToString = "English" Then
            INIs.INI_WriteValueToFile("PS Multi Tools", "Language", "EN", ".\conf.ini")
        ElseIf LangBox.SelectedItem.ToString = "Français" Then
            INIs.INI_WriteValueToFile("PS Multi Tools", "Language", "FR", ".\conf.ini")
        ElseIf LangBox.SelectedItem.ToString = "Deutsch" Then
            INIs.INI_WriteValueToFile("PS Multi Tools", "Language", "DE", ".\conf.ini")
        ElseIf LangBox.SelectedItem.ToString = "Letzebuergesch" Then
            INIs.INI_WriteValueToFile("PS Multi Tools", "Language", "LU", ".\conf.ini")
        End If

        MsgBox("Done", MsgBoxStyle.OkOnly)

    End Sub

    Private Sub UninstallLib_Click(sender As Object, e As EventArgs) Handles UninstallLib.Click

        Library.Clear_Old_Lib()

        'Throws an error when removing a library while you have one opened
        If LibraryList.SelectedItem = "PS2" Then
            If File.Exists(".\librarys\ps2-lib.dll") Then
                File.Delete(".\librarys\ps2-lib.dll")
                MsgBox(INIs.GetStringOfLang("Settings", "LibraryUninstalled").ToString.Split("|")(0), MsgBoxStyle.Information, INIs.GetStringOfLang("Settings", "LibraryUninstalled").ToString.Split("|")(1))
            Else
                MsgBox(INIs.GetStringOfLang("Settings", "LibraryNotInstalled").ToString.Split("|")(0), MsgBoxStyle.Critical, INIs.GetStringOfLang("Settings", "LibraryNotInstalled").ToString.Split("|")(1))
            End If
        ElseIf LibraryList.SelectedItem = "PS3" Then
            If File.Exists(".\librarys\ps3-lib.dll") Then
                File.Delete(".\librarys\ps3-lib.dll")
                MsgBox(INIs.GetStringOfLang("Settings", "LibraryUninstalled").ToString.Split("|")(0), MsgBoxStyle.Information, INIs.GetStringOfLang("Settings", "LibraryUninstalled").ToString.Split("|")(1))
            Else
                MsgBox(INIs.GetStringOfLang("Settings", "LibraryNotInstalled").ToString.Split("|")(0), MsgBoxStyle.Critical, INIs.GetStringOfLang("Settings", "LibraryNotInstalled").ToString.Split("|")(1))
            End If
        ElseIf LibraryList.SelectedItem = "PS4" Then
            If File.Exists(".\librarys\ps4-lib.dll") Then
                File.Delete(".\librarys\ps4-lib.dll")
                MsgBox(INIs.GetStringOfLang("Settings", "LibraryUninstalled").ToString.Split("|")(0), MsgBoxStyle.Information, INIs.GetStringOfLang("Settings", "LibraryUninstalled").ToString.Split("|")(1))
            Else
                MsgBox(INIs.GetStringOfLang("Settings", "LibraryNotInstalled").ToString.Split("|")(0), MsgBoxStyle.Critical, INIs.GetStringOfLang("Settings", "LibraryNotInstalled").ToString.Split("|")(1))
            End If
        ElseIf LibraryList.SelectedItem = "PSP" Then
            If File.Exists(".\librarys\psp-lib.dll") Then
                File.Delete(".\librarys\psp-lib.dll")
                MsgBox(INIs.GetStringOfLang("Settings", "LibraryUninstalled").ToString.Split("|")(0), MsgBoxStyle.Information, INIs.GetStringOfLang("Settings", "LibraryUninstalled").ToString.Split("|")(1))
            Else
                MsgBox(INIs.GetStringOfLang("Settings", "LibraryNotInstalled").ToString.Split("|")(0), MsgBoxStyle.Critical, INIs.GetStringOfLang("Settings", "LibraryNotInstalled").ToString.Split("|")(1))
            End If
        ElseIf LibraryList.SelectedItem = "PSV" Then
            If File.Exists(".\librarys\psv-lib.dll") Then
                File.Delete(".\librarys\psv-lib.dll")
                MsgBox(INIs.GetStringOfLang("Settings", "LibraryUninstalled").ToString.Split("|")(0), MsgBoxStyle.Information, INIs.GetStringOfLang("Settings", "LibraryUninstalled").ToString.Split("|")(1))
            Else
                MsgBox(INIs.GetStringOfLang("Settings", "LibraryNotInstalled").ToString.Split("|")(0), MsgBoxStyle.Critical, INIs.GetStringOfLang("Settings", "LibraryNotInstalled").ToString.Split("|")(1))
            End If
        ElseIf LibraryList.SelectedItem = "Tools" Then
            If File.Exists(".\librarys\tools-lib.dll") Then
                File.Delete(".\librarys\tools-lib.dll")
                MsgBox(INIs.GetStringOfLang("Settings", "LibraryUninstalled").ToString.Split("|")(0), MsgBoxStyle.Information, INIs.GetStringOfLang("Settings", "LibraryUninstalled").ToString.Split("|")(1))
            Else
                MsgBox(INIs.GetStringOfLang("Settings", "LibraryNotInstalled").ToString.Split("|")(0), MsgBoxStyle.Critical, INIs.GetStringOfLang("Settings", "LibraryNotInstalled").ToString.Split("|")(1))
            End If
        End If

        Library.Check_Librarys()

    End Sub

    Private Sub LibraryManagerButton_Click(sender As Object, e As EventArgs) Handles LibraryManagerButton.Click
        LibraryManager.Show()
        Me.Close()
    End Sub

End Class